package com.hzzh.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hzzh.service.EmployeeService;
import com.hzzh.vo.Employee;



/**
 * Servlet implementation class UpdateServlet
 */
@WebServlet("/UpdateServlet")
public class UpdateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
		}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String username=request.getParameter("username");
		String password=request.getParameter("passwordd");
		EmployeeService us= new EmployeeService();
		Employee u1=new Employee();
		try {
			String msg = "";
			if("".equals(password)){
				msg = "密码不能为空";
				request.setAttribute("msg", msg);
				request.getRequestDispatcher("updatepassword.jsp").forward(request, response);
			}else if(password.equals(request.getParameter("password"))){
				msg = "密码重复";
				request.setAttribute("msg", msg);
				request.getRequestDispatcher("updatepassword.jsp").forward(request, response);
			}else{
				u1.setUsername(username);
				u1.setPassword(password);
				us.updateUserService(u1);
				request.getRequestDispatcher("login.jsp").forward(request, response);
			}
			
		}
		catch (ClassNotFoundException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		};
		
	}

}
